<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018-04-25
 * Time: 22:33
 */

namespace app\cls\tom\log;


use app\cls\tom\SysResource;

/**
 * 表字段
 * ===========================
 * id ID int
 * keyword 关键字 varchar 20
 * log_type 日志类型 1 普通日志 tinyint
 * msg 日志消息 varchar 200
 * detail 日志详情 varchar 1000
 * add_time 添加时间 datetime
 * ===========================
 *
 * Class DbLog
 * @package app\cls\tom\log
 */
class DbLog extends LogBase
{
    public $db;
    public $table = "tom_log";
    public function write()
    {
        if(empty($this->msg) && empty($this->detail)){
            return ;
        }
        if(empty($db)){
            $this->db = SysResource::getDB(true);
        }
        $db = $this->db;
        $db->insert($this->table,[
            "keyword"=>$this->getKeyWordMsg(),
            "msg"=>$this->msg,
            "detail"=>$this->getDetail(),
            "log_type"=>$this->type,
            "add_time"=>date("Y-m-d H:i:s")
        ]);
    }
}